package com.ist.smartstation;

import com.ist.smartstation.entity.Passenger;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class SmartStation extends Activity {
	
	private static final int BOOK_ID = Menu.FIRST;
	private static final int PASSENGERLIST_ID = BOOK_ID + 1;
	
	private static final int REGISTER_ACTIVITY_CREATE=0;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if(requestCode == REGISTER_ACTIVITY_CREATE){
			if(resultCode == RESULT_OK){
				collectRegisterData(data);
			}
		}
	}
    
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		menu.add(0, BOOK_ID, 0, "Book");//.setIcon(R.drawable.info);
		menu.add(0, PASSENGERLIST_ID, 1, "Passengers");//.setIcon(R.drawable.info);
		return true;
	}

	@Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		switch(item.getItemId()) {
		case BOOK_ID:
			Intent register = new Intent(this, RegisterActivity.class);
			startActivityForResult(register, REGISTER_ACTIVITY_CREATE);
			return true;
		case PASSENGERLIST_ID:
			Intent list = new Intent(this, PassengerListActivity.class);
			startActivity(list);
			return true;
		}
		return super.onMenuItemSelected(featureId, item);
	}
	
	private void collectRegisterData(Intent data) {
		Passenger passenger = (Passenger) data.getSerializableExtra("passenger");
		Toast.makeText(this, passenger.toString(), 3).show();
	}
}